package lt.ntec.danblog.server.core;

import lt.ntec.danblog.server.core.model.Comment;
import lt.ntec.danblog.server.core.validator.AbstractValidator;
import lt.ntec.danblog.server.core.validator.Rule;
import lt.ntec.danblog.server.core.validator.Validable;
import lt.ntec.danblog.server.core.validator.rules.GuestTextContent;

public class CommentValidator extends AbstractValidator implements Validable {

    @Override
    public boolean isValid(Object object) {
        if (!(object instanceof Comment)) {
            messages.add(new Message(Messageable.Type.NOTICE, "Wrong type"));
            return false;
        }

        Comment comment = (Comment) object;

        boolean isValid = true;

        Rule content = new GuestTextContent();

        if (!content.isValid(comment.getContent())) {
            messages.add(content.getMessage());
            isValid = false;
        }

        return true & isValid;
    }
}
